package com.xindz.hgq.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;

import com.xindz.hgq.R;
import com.xindz.hgq.adapter.ViewPagerAdapter;
import com.xindz.hgq.base.BaseActivity;
import com.xindz.hgq.base.options.BaseActivityOptions;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * @name HGQBase
 * @class name：com.xindz.hgq.fragment
 * @describe describe
 * @anthor XINDZ
 * @time 2018/1/16 11:56
 * @change
 * @chang time
 * @class describe
 */
public class DefaultFragmetActivity extends BaseActivity {
    @BindView(R.id.tl_frag_default)
    TabLayout tlFragDefault;
    @BindView(R.id.vp_frag_default)
    ViewPager vpFragDefault;
    private Unbinder bind;

    private ArrayList<String> titleList = new ArrayList<>();
    private ArrayList<Fragment> fragmentList = new ArrayList<>();
    private DefaultFragment defaultFragment;
    private MvpFragment mvpFragment;
    private LoadSirFragment loadSirFragment;
    private ViewPagerAdapter adapter;

    @Override
    public BaseActivityOptions setOption() {
        return null;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frg_default);
        bind = ButterKnife.bind(this);

        titleList.add("默认");
        defaultFragment = new DefaultFragment();
        fragmentList.add(defaultFragment);

        titleList.add("MVP");
        mvpFragment = new MvpFragment();
        fragmentList.add(mvpFragment);

        titleList.add("LoadSir");
        loadSirFragment = new LoadSirFragment();
        fragmentList.add(loadSirFragment);

        tlFragDefault.setTabMode(TabLayout.MODE_FIXED);
        tlFragDefault.setTabGravity(TabLayout.GRAVITY_FILL);
        for (String tab : titleList) {
            tlFragDefault.addTab(tlFragDefault.newTab().setText(tab));
        }
        tlFragDefault.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                vpFragDefault.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        adapter = new ViewPagerAdapter(getSupportFragmentManager(), titleList, fragmentList);

        vpFragDefault.setAdapter(adapter);

        tlFragDefault.setupWithViewPager(vpFragDefault);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        bind.unbind();
    }
}
